/*
 * KineticsSolver.h
 *
 *  Created on: 28 Jul 2011
 *      Author: Allan
 */

#ifndef KINETICSSOLVER_H_
#define KINETICSSOLVER_H_

// C++ includes
#include <vector>
using namespace std;

// GeoReact includes
#include "Multiphase.h"
#include "ReactionSystem.h"
#include "OdeSolver.h"
#include "EquilibriumSolver/EquilibriumSolver.h"

// GeoReact forward declarations
class KineticsProblem;

class KineticsSolver
{
public:
	KineticsSolver();
	
	KineticsSolver(const Multiphase& multiphase, const ReactionSystem& eReactions, const ReactionSystem& kReactions);
	
	void 
	SetControlSolution(double epsRel);
	
	const bool
	Iterate(double& t, double tEnd, double& dt, double T, double P, VectorXd& n);
	
	const bool
	Solve(double& t, double tEnd, double& dt, double T, double P, VectorXd& n);
	
private:
	Multiphase multiphase;
	
	ReactionSystem eReactions, kReactions;
	
	MatrixXd vej, vkj;
	
	vector<Index> jIndexes, eIndexes, kIndexes;
	
	uint Nj, Ne, Nk;
	
	VectorXd nj, ne, nk;
	
	VectorXd uj, ujnk;
	
	OdeSolver odeSolver;
	
	EquilibriumSolver eSolver;
	
	/// --- Friend classes --- ///
	friend class KineticsProblem;
};

class KineticsProblem : public OdeProblem
{
public:
	KineticsProblem(KineticsSolver& kSolver, double T, double P, const VectorXd& n);
	
	virtual void 
	Function(double t, const VectorXd& ujnk, VectorXd& R);
	
private:
	KineticsSolver& kSolver;
	
	double T, P;
	
	VectorXd n, a;
	
	VectorXd Rk;
};

#endif /* KINETICSSOLVER_H_ */
